#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <cblas.h>
#include "defs.h"
void dgemm_naive(int m, int n, int k,int alpha ,int beta,
          double A[][k+1], double B[][n], double C[][n]);

int main(int argc, char *argv[])
{
  if (argc < 2)
  {
    printf("Input Error\n");
    return 1;
  }

  printf("test!\n");
  int i, m, n, k;
  m = n = k = atoi(argv[1]);

  int sizeofa = m * k;
  int sizeofb = k * n;
  int sizeofc = m * n;
  int lda = m;
  int ldb = k;
  int ldc = m;

  double alpha = 1.0;
  double beta = 1.0;

  double *A = (double *)malloc(sizeof(double) * sizeofa);
  double *B = (double *)malloc(sizeof(double) * sizeofb);
  double *C = (double *)malloc(sizeof(double) * sizeofc);

    int rc = fork();
    if (rc < 0) {
        // fork failed; exit
        fprintf(stderr, "fork failed\n");
        exit(1);
    } else if (rc == 0) {
        // child (new process)
    dgemm_naive(m, n, k, alpha,beta,
          A, B, C);
    } else {
        // parent goes down this path (original process)
    dgemm_naive(m, n, k,alpha, beta,
          A, B, C);
    }
    free(A);
    free(B);
    free(C);
    return 0;
}

void dgemm(int m, int n, int k, int alpha,int beta,
          double A[][k+1], double B[][n], double C[][n]){
    for(int i=0; i< m;i ++){    //C[i] 
        for(int j=0; j< n; j++){  //C[i][j]
            C[i][j] = beta*C[i][j];
            for(int p=0; p< k; p++){  
                C[i][j] += alpha*A[i][p]*B[p][j]; 
             }
        }
    }
}